<template>
  <div class="widget">
    <div class="widget-toolbar">
      {{widget.title}}-挂件
      <span @click.stop="showConf"><icon name="cog" class="widget-setting"></icon></span>
    </div>
    <div class="widget-content">
      <examine-time v-if="widget.code === 'examine-time'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></examine-time>
      <report-sn v-if="widget.code === 'report-sn'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></report-sn>
      <null-space v-if="widget.code === 'null-space'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></null-space>
      <user-info v-if="widget.code === 'user-info'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></user-info>
      <tizhi-a v-if="widget.code === 'tizhi-a'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></tizhi-a>
      <tizhi-b v-if="widget.code === 'tizhi-b'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></tizhi-b>
      <tizhi-c v-if="widget.code === 'tizhi-c'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></tizhi-c>
      <tizhi-d v-if="widget.code === 'tizhi-d'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></tizhi-d>
      <tizhi-e v-if="widget.code === 'tizhi-e'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></tizhi-e>
      <fangan-a v-if="widget.code === 'fangan-a'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-a>
      <fangan-b v-if="widget.code === 'fangan-b'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-b>
      <fangan-c v-if="widget.code === 'fangan-c'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-c>
      <fangan-d v-if="widget.code === 'fangan-d'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-d>
      <fangan-e v-if="widget.code === 'fangan-e'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-e>
      <fangan-f v-if="widget.code === 'fangan-f'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-f>
      <fangan-g v-if="widget.code === 'fangan-g'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-g>
      <fangan-h v-if="widget.code === 'fangan-h'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-h>
      <fangan-i v-if="widget.code === 'fangan-i'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></fangan-i>
      <jk-record v-if="widget.code === 'jk-record'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></jk-record>
      <report-intro v-if="widget.code === 'report-intro'" :widget="widget" :showConfDialog="showConfDialog" @done="confDone" v-on:save="savePage"></report-intro>
    </div>
  </div>
</template>

<script>
  import NullSpace from "./null-space";
  import UserInfo from "./user-info";
  import TizhiA from "./tizhi-a";
  import TizhiB from "./tizhi-b";
  import TizhiC from "./tizhi-c";
  import TizhiD from "./tizhi-d";
  import TizhiE from "./tizhi-e";
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import FanganA from "./fangan-a";
  import FanganB from "./fangan-b";
  import FanganC from "./fangan-c";
  import FanganD from "./fangan-d";
  import FanganE from "./fangan-e";
  import FanganF from "./fangan-f";
  import FanganG from "./fangan-g";
  import FanganH from "./fangan-h";
  import ExamineTime from "./examine-time";
  import ReportSn from "./report-sn";
  import FanganI from "./fangan-i";
  import JkRecord from "./jk-record";
  import ReportIntro from "./report-intro";

  export default {
    components: {
      ReportIntro,
      JkRecord,
      FanganI,
      ReportSn,
      ExamineTime,
      FanganH,
      FanganG,
      FanganF,
      FanganE,
      FanganD,
      FanganC,
      FanganB,
      FanganA,
      TizhiE,
      TizhiD,
      TizhiC,
      TizhiB,
      TizhiA,
      UserInfo,
      NullSpace },
    name: "widget",
    props:['widget'],
    data(){
      return {
        showConfDialog:false,
      }
    },
    methods:{
      ...mapActions({
        fetch: 'fetch'
      }),
      showConf(e){
        console.log('挂件里的show————————————',e)
        this.showConfDialog = true
      },
      confDone(p){
        console.log('挂件里的————————————',p)
        this.showConfDialog = false
        if(p){
          //console.log(p,this.widget)
          //保存配置
          this.fetch({name:'updateWidget',data:{
              id:this.widget.id,
              title:this.widget.title,
              config:JSON.stringify(this.widget.config),
              code:this.widget.code,
              enabled:this.widget.enabled,
              description:this.widget.description}})
        }
      },
      savePage(p){
        console.log('挂件首页',p)
        this.$emit('done', p)
      }
    }
  }
</script>

<style lang="scss">
  .widget{
    border:1px solid #a4a4a4;
    margin:5px 0;
    padding:4px;
    .widget-toolbar{
      border-bottom:1px solid #e4e4e4;
      height:26px;
      font-weight: bold;
      .widget-setting{
        float:right;
        color:#e4e4e4;
        cursor: pointer;
        &:hover{color:#666;}
        &:after{clear:both;}
      }
    }
    .widget-content{
      margin:5px 0;
    }
  }
</style>
